<?php  defined('BASEPATH') OR exit('No direct script access allowed');

class Articles_model extends MY_Model {

	protected $_table = 'articles';
	protected $lang_table = 'articles_lang';

	public function delete($id = 0)
	{
		return parent::_delete($id);
	}
	
	function search($keyword , $category = 0, $active = 0, $limit = array())
	{
		$this->db
		->select($this->profile_table.'.*, g.description as group_name, users.*')
		->select('IF('.$this->profile_table.'.last_name = "", '.$this->profile_table.'.first_name, CONCAT('.$this->profile_table.'.first_name, " ", '.$this->profile_table.'.last_name)) as full_name', FALSE)
		->join('groups g', 'g.id = users.group_id')
		->join('profiles', 'profiles.user_id = users.id', 'left')
		->group_by('users.id');
	
		if("" != trim($keyword))
		{
	
			$this->db->like('users.username', trim($keyword), 'both');
		}
	
		if(0 != intval($category))
		{
			$this->db->where('users.group_id', intval($category));
		}
	
		if(0 != intval($active))
		{
			$this->db->where('users.active', intval($active));
		}
		$this->limit($limit);
		return $this->db->get('users')->result();
	}
	
	function count_search($keyword , $category = 0, $active = 0)
	{
		$this->db
		->from('users')
		->join('groups g', 'g.id = users.group_id')
		->join('profiles', 'profiles.user_id = users.id', 'left');
	
		if("" != trim($keyword))
		{
	
			$this->db->like('users.username', trim($keyword), 'both');
		}
	
		if(0 != intval($category))
		{
			$this->db->where('users.group_id', intval($category));
		}
	
		if(0 != intval($active))
		{
			$this->db->where('users.active', intval($active));
		}
		return $this->db->count_all_results();
	}
}

/* End of file file_regions_m.php */